<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>MathJax Generator</title>
    <link rel="stylesheet" href="/afx/resource/css/?p=css/reset.css">
    <style>
        #formula {
            display: inline-block !important;
        }

        .MathJax, .MathJax_Preview, .MathJax_PHTML {
            font-size: 1.3em !important;
        }

        .MathJax_Display, .MJXp-display {
            margin: 0 !important;
        }

    </style>
</head>
<body>

<div id="formula">...</div>
<script src="/afx/resource/js/?p=js/jquery.js" type="text/javascript"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
  messageStyle: "none",
  showMathMenu: true,
  tex2jax: {
    inlineMath: [["$","$"], ["\\(","\\)"]],
    displayMath: [["$$","$$"], ["\\[", "\\]"]],
    ignoreClass: "nostem|nolatexmath"
  },
  asciimath2jax: {
    delimiters: [['`','`'], ['\\$','\\$']],
    ignoreClass: "nostem|nolatexmath"
  },
  mml2jax: {
    ignoreClass: "nostem|nolatexmath"
  },
  TeX: { equationNumbers: { autoNumber: "AMS" } },
  extensions: ["tex2jax.js","mml2jax.js","asciimath2jax.js"],
  jax: ["input/TeX","input/MathML","input/AsciiMath","output/PreviewHTML"]
});

</script>
<script src="/afx/dynamic/mathjax/MathJax.js"></script>
<script type="text/javascript">

    function Atom(formula, imagesDir, imageTarget) {
        this.formula = formula;
        this.imagesDir = imagesDir;
        this.imageTarget = imageTarget;
        this.hashCode = function () {
            return (this.formula + this.imagesDir + this.imageTarget);
        }
    }

    var atoms = [];
    var cache = {};
    var starter = Promise.resolve();
    function processFormula(formula, imagesDir, imageTarget) {

        atoms.push(new Atom(formula, imagesDir, imageTarget));

        starter = starter.then(function () {
            return new Promise(function (resolved, rejected) {

                var popped = atoms.pop();

                if (!popped) {
                    resolved();
                    return;
                }

                var element = document.querySelector("#formula");

                if (element.innerHTML == popped.formula) {
                    resolved();
                    return;
                }

                var cacheHit = cache[popped.imageTarget];
                var hashCode = popped.hashCode();

                if (cacheHit && cacheHit == hashCode) {
                    resolved();
                    return;
                }

                element.innerHTML = popped.formula;

                if ((typeof MathJax) != "undefined") {
                    MathJax.Hub.Queue(["Typeset", MathJax.Hub], function () {
                        try {
                            afx.snapshotFormula(popped.formula, popped.imagesDir, popped.imageTarget);
                            cache[popped.imageTarget] = hashCode;
                        }
                        catch (e) {
                            // handled in java code
                        }
                        resolved();
                    });
                }
                else {
                    resolved();
                }

            });
        });
    }
</script>
<!--<script src="/afx/resource/js/?p=js/firebug-import.js"></script>-->
</body>
</html>